#include<bits/stdc++.h>
using namespace std;

int d[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

void fun(int n)
{
	priority_queue<int, vector<int>, greater<int>> q;
	for(int i = 1;i <= 12;i++)
	{
		for(int j = 1;j <= d[i];j++)
		{
			int t = (j%10*1000+j/10*100+i%10*10+i/10);
			t = t*10000+i*100+j;
			if(t > n)
			q.push(t);
		}
	}
	
	cout<<q.top()<<endl;
	
	while(!q.empty())
	{
		string s = to_string(q.top());
		
		if(s[0] == s[2] && s[2] == s[5] && s[5] == s[7] && s[1] == s[3] && s[3] == s[4] && s[4] == s[6])
		{
			cout<<s;
			break;
		}
		q.pop();
	}
}

int main()
{
	int data;
	cin>>data;
	
	fun(data);
	return 0;
}

